package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class NursingProjectImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 根据条件分页查询护理项目
     * @param name 护理项目名称
     * @param pageNum 当前页数
     * @param pageSize 每页显示数量
     * @param status 状态
     * @return 分页查询结果
     */
    @Override
    public PageResponse<NursingProjectVo> selectByPage(
            String name, Integer pageNum, Integer pageSize, Integer status) {

        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProjectVo> page =
                nursingProjectMapper.getByPage(name,status);
        return PageResponse.of(page, NursingProjectVo.class);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDTO 护理项目DTO
     */
    @Override
    public void insert(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.copyProperties(nursingProjectDTO, NursingProject.class);
        nursingProjectMapper.addNursingProject(nursingProject);
    }


    /**
     * 编辑护理项目
     * @param nursingProjectDTO 护理项目DTO
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.copyProperties(nursingProjectDTO, NursingProject.class);
        nursingProjectMapper.updateNursingProject(nursingProject);
    }


    /**
     * 启用和禁用
     * @param id 护理项目id
     * @param status 状态
     */
    @Override
    public void enableAndDisable(Long id, Integer status) {
        nursingProjectMapper.enableAndDisable(id, status);
    }


    /**
     * 根据id查询护理项目
     * @param id 护理项目id
     * @return 护理项目VO
     */
    @Override
    public NursingProjectVo getById(Long id) {
        return nursingProjectMapper.getById(id);
    }


    /**
     * 根据id删除护理项目
     * @param id 护理项目id
     */
    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

    /**
     * 查询所有护理项目
     * @return 护理项目VO列表
     */
    @Override
    public List<NursingProjectVo> getAll() {
        return nursingProjectMapper.getAll();
    }
}
